package com.hrt.myprestocode;

import java.sql.*;

//通过JDBC方式连接Presto
public class JDBCPresto {
    public static void main(String[] args) throws SQLException {
        //获取连接
        Connection conn = DriverManager.getConnection("jdbc:presto://node3:8080/mysql/presto_db","root","");

        //准备查询语句
        PreparedStatement pst = conn.prepareStatement("select pkg_name,sum(amount) as total_amount from machine_consume_detail " +
                "group by pkg_name");

        ResultSet rst = pst.executeQuery();
        while(rst.next()){
            String pkgName = rst.getString("pkg_name");
            double totalAmount = rst.getDouble("total_amount");

            System.out.println("pkgName = "+pkgName+",totalAmount = "+totalAmount);
        }

        pst.close();
        conn.close();


    }
}
